## Analyze experimental data

## Loading packages
library(tidyverse)
library(coefplot)

## Loading data
exp = read.csv("experimental.csv")

## Table A12 ##
prop.table(table(exp$income))
prop.table(table(exp$education))
prop.table(table(exp$female))
prop.table(table(exp$white))
prop.table(table(exp$black))
prop.table(table(exp$hispanic))
prop.table(table(exp$ideology))
prop.table(table(exp$partyid))
prop.table(table(exp$age))
prop.table(table(exp$interest))

## Figure A3 ##
summary(balance<-lm(treated ~ female + age + education + income + 
                      white + black + hispanic + ideology + partyid + interest,
                    data = exp))

balance <- coefplot(balance, 
                    ylab = "", xlab = "Coefficient", title = NULL,
                    intercept = FALSE, innerCI = 0) + 
  theme_bw() +
  scale_y_discrete(labels=c("Female", "Age", "Education", "Income", "White", "Black", "Hispanic",
                            "Ideology", "Party", "Interest"))
ggsave(balance, file = "balance_exp.png", 
       width = 4, height = 3.5, units = "in", dpi = 800)

## Table 2 ##
summary(m1<-lm(vote ~ treated, data = exp))
summary(m2<-lm(approval ~ treated, data = exp))
summary(m3<-lm(effectiveness ~ treated, data = exp))
summary(m4<-lm(represent ~ treated, data = exp))
summary(m5<-lm(notice ~ treated, data = exp))
summary(m6<-lm(affected ~ treated, data = exp))

## Table A13 ##
summary(m1_cov<-lm(vote ~ treated + female + age + education + income + 
                     white + black + hispanic + ideology + partyid + interest, data = exp))
summary(m2_cov<-lm(approval ~ treated + female + age + education + income + 
                     white + black + hispanic + ideology + partyid + interest, data = exp))
summary(m3_cov<-lm(effectiveness ~ treated + female + age + education + income + 
                     white + black + hispanic + ideology + partyid + interest, data = exp))
summary(m4_cov<-lm(represent ~ treated + female + age + education + income + 
                     white + black + hispanic + ideology + partyid + interest, data = exp))
summary(m5_cov<-lm(notice ~ treated + female + age + education + income + 
                     white + black + hispanic + ideology + partyid + interest, data = exp))
summary(m6_cov<-lm(affected ~ treated + female + age + education + income + 
                     white + black + hispanic + ideology + partyid + interest, data = exp))









